//
//  DDOrderSectionFooter.m
//  Dingdong
//
//  Created by 程强 on 16/11/15.
//  Copyright © 2016年 程强. All rights reserved.
//

#import "DDOrderSectionFooter.h"

@interface DDOrderSectionFooter ()
@property (strong, nonatomic) UIButton *leftBtn;
@property (strong, nonatomic) UIButton *rightBtn;
@property (strong, nonatomic) OrderOperation leftBlock;
@property (strong, nonatomic) OrderOperation rightBlock;
@end

@implementation DDOrderSectionFooter

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        KKLabel *priceTitleLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"The order amount:",RGBColor(85, 85, 85),[UIFont systemFontOfSize:12.0],NSTextAlignmentLeft);
        }];
        [self addSubview:priceTitleLbl];
        [priceTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self).offset(10);
            make.centerY.equalTo(self);
            make.width.equalTo(@110);
            make.height.equalTo(@25);
        }];
        
        self.priceLbl = [[KKLabel alloc]initWithBlock:^(KKLabel *lbl) {
            lbl.laText(@"$120",kRedColor,[UIFont systemFontOfSize:12.0],NSTextAlignmentLeft);
        }];
        [self addSubview:_priceLbl];
        [_priceLbl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.left.equalTo(priceTitleLbl.mas_right).offset(0);
            make.width.equalTo(@80);
            make.height.equalTo(@30);
        }];
     
        self.rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_rightBtn];
        [_rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _rightBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        [_rightBtn setBackgroundColor:kRedColor];
        _rightBtn.layer.cornerRadius = 2.0;
        [_rightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.height.equalTo(@30);
            make.width.equalTo(@80);
            make.right.equalTo(self).offset(-15);
        }];
        [_rightBtn addTarget:self action:@selector(rightClick:) forControlEvents:UIControlEventTouchUpInside];
        
        self.leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [self addSubview:_leftBtn];
        [_leftBtn setTitleColor:RGBColor(44, 44, 44) forState:UIControlStateNormal];
        [_leftBtn setBackgroundColor:RGBColor(238, 238, 238)];
        _leftBtn.layer.cornerRadius = 2.0;
        _leftBtn.titleLabel.font = [UIFont systemFontOfSize:15.0];
        [_leftBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self);
            make.height.equalTo(@30);
            make.width.equalTo(@80);
            make.right.equalTo(_rightBtn.mas_left).offset(-15);
        }];
        [_leftBtn addTarget:self action:@selector(leftClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return self;
}
- (void)setOrderStatus:(kOrderStatus)orderStatus
{
    _orderStatus = orderStatus;
    NSString *leftTitle = @"";
    NSString *rightTitle = @"";
    if (orderStatus == kOrderStatusPending) {
        leftTitle = @"Pay";
        rightTitle = @"Cancel";
        self.leftBtn.hidden = YES;
        self.rightBtn.hidden = NO;
    }else if (orderStatus == kOrderStatusShipped){
        leftTitle = @"Cancel";
        rightTitle = @"Confirm";
        self.leftBtn.hidden = YES;
        self.rightBtn.hidden = NO;
    }else if (orderStatus == kOrderStatusComplete||orderStatus == kOrderStatusReceived){
        leftTitle = @"Evaluate";
        rightTitle = @"Buy agagin";
        self.leftBtn.hidden = YES;
        self.rightBtn.hidden = YES;
    }else if (orderStatus == kOrderStatusCancel){
        self.leftBtn.hidden = YES;
        self.rightBtn.hidden = YES;
    }
    [self.leftBtn setTitle:leftTitle forState:UIControlStateNormal];
    [self.rightBtn setTitle:rightTitle forState:UIControlStateNormal];
}
- (void)leftClick:(UIButton *)btn
{
    if (self.leftBlock) {
        self.leftBlock();
    }
}
- (void)rightClick:(UIButton *)btn
{
    if (self.rightBlock) {
        self.rightBlock();
    }
}
- (void)setOrderOperation:(OrderOperation)leftOperation right:(OrderOperation)rightOperation
{
    self.leftBlock = leftOperation;
    self.rightBlock = rightOperation;
}
@end
